<?php

namespace app\api\controller\v1;

use app\common\controller\Api;
use think\Db;

class Attendance extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function query()
    {
        $dateStart = $this->request->get('date_start');
        $dateEnd = $this->request->get('date_end');
        $keyword = $this->request->get('keyword');
        try {
            $where = [];
            if ($dateStart) $where['checkin_time'] = ['>=', $dateStart];
            if ($dateEnd) $where['checkout_time'] = ['<=', $dateEnd];
            $rows = Db::name('course_attendance')->where($where)->field('user_id as account,username as name,checkin_time as time,school_name as school,class_name as class,checkin_time,checkout_time')->order('checkin_time desc')->limit(200)->select();
            return json(['code' => 200, 'msg' => 'OK', 'data' => $rows]);
        } catch (\Exception $e) {
            return json(['code' => 500, 'msg' => $e->getMessage(), 'data' => []]);
        }
    }
}